package orderhandler

import (
	"github.com/gin-gonic/gin"
	"yundian/internel/app/logic"
	"yundian/internel/pkg/dingo"
	. "yundian/internel/pkg/dingo/result"
)

// 取消旧订单
func HandelCancelYdOldOrder(ctx *gin.Context) {
	// 获取参数
	param := &struct {
		TradeNo    string `json:"tradeNo" binding:"required"`
	}{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	err := logic.NewOrderLogic().HandleWxCancelOrderByYd(param.TradeNo)

	if err != nil {
		Response(ctx)("订单撤销失败", CodeSuccess, err)(OK)
		return
	}

	Response(ctx)("订单撤销成功", CodeSuccess, true)(OK)
}

// 取消旧订单
func HandelCancelZmOldOrder(ctx *gin.Context) {
	// 获取参数
	param := &struct {
		TradeNo    string `json:"tradeNo" binding:"required"`
	}{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	err := logic.NewOrderLogic().HandleWxCancelOrderByZm(param.TradeNo)

	if err != nil {
		Response(ctx)("订单撤销失败", CodeSuccess, err)(OK)
		return
	}

	Response(ctx)("订单撤销成功", CodeSuccess, true)(OK)
}

